package org.ccheng.common;

import cn.hutool.setting.Setting;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

public enum Config {

    USER("User");

    public static final Setting setting;
    public static final File FILE = new File("setting.ini");

    static {
        Setting setting_tmp = null;
        try {
            if (!FILE.exists()) {
                FILE.createNewFile();
            }
            setting_tmp = new Setting(FILE, Charset.defaultCharset(), false);
        } catch (IOException e) {
            throw new RuntimeException("请检查配置文件是否存在");
        }
        setting = setting_tmp;
    }

    private String sectionName;

    Config(String sectionName) {
        this.sectionName = sectionName;
    }

    public String getString(String key) {
        return setting.get(sectionName, key);
    }

    public void set(String key, String value) {
        setting.setByGroup(key, this.sectionName, value);
    }
}
